class_name Arena
extends Node2D

# ===============================================

@export var music: AudioStream

# ===============================================

const MAX_Z_INDEX: int = 99
const CELL_SIZE: Vector2 = Vector2(32, 32)
const HALF_CELL_SIZE: Vector2 = Vector2(16, 16)
const QUARTER_CELL_SIZE: Vector2 = Vector2(8, 8)

@onready var dust_particles: GPUParticles2D = $Visuals/DustParticles
@onready var unit_mover: UnitMover = $UnitMover
@onready var unit_spawner: UnitSpawner = $UnitSpawner
@onready var sell_portal: SellPortal = $SellPortal
@onready var shop: Shop = $UI/Shop
@onready var unit_combiner: UnitCombiner = $UnitCombiner
@onready var battle_unit_grid: UnitGrid = $GameArea/BattleUnitGrid
@onready var game_area: PLayArea = $GameArea

# ===============================================

func _ready() -> void:
	dust_particles.z_index = Arena.MAX_Z_INDEX
	unit_spawner.unit_spawned.connect(unit_mover.setup_unit)
	unit_spawner.unit_spawned.connect(sell_portal.setup_unit)
	unit_spawner.unit_spawned.connect(unit_combiner.queue_unit_combination_update.unbind(1))
	shop.unit_bought.connect(unit_spawner.spawn_unit)
	MusicPlayer.play(music)
	UnitNavigation.init(battle_unit_grid, game_area)
